package com.sise.wangzhan.client;

import com.netflix.hystrix.HystrixCircuitBreaker;
import com.netflix.hystrix.HystrixCommandKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname HelloController
 * @Description TODO
 * @Date 2020/5/6 22:16
 * @Created by wangzhan
 */
@RestController
public class HelloController {

    @Autowired
    HelloClient helloClient;

    @RequestMapping(value = "/feign/hello",method = RequestMethod.GET)
    public String feignHello(){
        // hello 方法会超时
        String helloRequest = helloClient.hello();
        // 获取断路器
        HystrixCircuitBreaker breaker = HystrixCircuitBreaker.Factory
                .getInstance(HystrixCommandKey.Factory.asKey("HelloClient#hello()"));
        System.out.println("断路器的状态：" + breaker.isOpen());

        return helloRequest;
    }
}
